package admin

import (
	"exercise/application/yiran/app/libs"
	"exercise/application/yiran/app/request"
	"exercise/application/yiran/app/service"
	"github.com/gin-gonic/gin"
)

type excelController struct {
}

// Import 导入excel
func (e excelController) Import(ctx *gin.Context) {
	request := new(request.ImportRequest)
	err := libs.BindRequest(ctx, request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}
	header, list, err := service.NewExcelService().Import(request)
	if err != nil {
		libs.Toast(ctx, err.Error())
		return
	}
	libs.Success(ctx, map[string]interface{}{"header": header, "list": list})
	return
}

func NewExcelController() *excelController {
	return &excelController{}
}
